﻿using LVYAN.Model;
using LVYAN.Model.AutoMation;
using LVYAN.Utils;
using System.Collections.Generic;
namespace LVYAN.Service.AIAPI
{
    /// <summary>
    /// 
    /// </summary>
    public class ContactsManage : BaseAPI
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static List<ContactTask> GetList(RobotModel Robot, RobotRobotOther RobotOther)
        {
            var Cache = new AIConfig().GetConfigModel(nameof(ContactsManage), nameof(GetList)).Cache;

            var content = JsonService.ToString(new
            {
                RobotName = Robot.RobotName,
                RobotCode = Robot.RobotCode,
                MacAddress = WinInfo.GetMacAddress(),
                MacIP = WinInfo.GetIP(),
                MacName = WinInfo.GetHostName(),
            });

            var Result = CacheManage<List<ContactTask>>.GetCache(content, () =>
            {
                new LoggerService().ResponseMsgDebug("手机号管理", "发送消息-手机号", content);
                var result = new RequestService().PostJson($"{AIAPI}api/aichat/getRobotContactsList", content);
                var reponseData = JsonService.ToModel<ReponseData<List<ContactTask>>>(result);
                reponseData.Data.ForEach(t => t.TaskId = new SignService().MD5ToLower($"{t.Key}"));
                new LoggerService().ResponseMsgDebug("手机号管理", "接受消息-手机号", reponseData);
                return reponseData.Data;
            }, Cache);
            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static void SendFriend(RobotModel Robot, ContactTask  contact, ApplyType applyType)
        {
            var content = JsonService.ToString(new
            {
                RobotName = Robot.RobotName,
                RobotCode = Robot.RobotCode,
                MacAddress = WinInfo.GetMacAddress(),
                MacIP = WinInfo.GetIP(),
                MacName = WinInfo.GetHostName(),
                Key = contact.Key,
                NickName = contact.NickName,
                StatusInt = applyType,
                StatusText= applyType.ToString(),
            });
            new LoggerService().ResponseMsgDebug("手机号管理", "发送消息-手机号", content);
            var result = new RequestService().PostJson($"{AIAPI}api/aichat/SendFriend", content);
            var reponseData = JsonService.ToModel<ReponseData<List<ContactTask>>>(result);
            new LoggerService().ResponseMsgDebug("手机号管理", "接受消息-手机号", reponseData);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static void TongBuFriend(RobotModel Robot, RobotRobotOther RobotOther, List<RoomModel> requestList)
        {
            var content = JsonService.ToString(new
            {
                RobotName = Robot.RobotName,
                RobotCode = Robot.RobotCode,
                MacAddress = WinInfo.GetMacAddress(),
                MacIP = WinInfo.GetIP(),
                MacName = WinInfo.GetHostName(),
                RobotOther.TenantID,
                RequestList = requestList,
            });
            //new LoggerService().ResponseMsgDebug("同步微信好友", "发送消息-通讯录", content);
            var result = new RequestService().PostJson($"{AIAPI}api/aichat/TongBuFriend", content);
            var reponseData = JsonService.ToModel<ReponseData>(result);
            new LoggerService().ResponseMsgDebug("同步微信好友", "接受消息-通讯录", reponseData);
        }
    }
}
